/*
 * InformationPanel.java
 *
 * Created on February 15, 2008, 2:37 AM
 */

package gui.operation;

import datamodel.WSFOperation;
import java.awt.Color;

/**
 *
 * @author  chang
 */
public class InformationPanel extends javax.swing.JPanel {
    private WSFOperation operation;
    /** Creates new form InformationPanel */
    public InformationPanel(WSFOperation operation) {
        this.operation = operation;
        initComponents();
        showOperation();
    }
    
    public void setOperation(WSFOperation operation){
        this.operation = operation;
        showOperation();
    }
    
    private void showOperation(){
        
        if(operation.isSupported()){
            supportedPanel.setBackground(new Color(0,170,110));
            supportedPanel.setText("Supported");
        }else{
            supportedPanel.setBackground(new Color(200,50,0));
            supportedPanel.setText("Not Supported: " + operation.getCause());
        }
        
        if(operation.getPort().getBindingType().equalsIgnoreCase("httpbinding")){
            showHTTPOperationInformationPanel();
            return;
        }
        
        if(operation.getPort().getBindingType().equalsIgnoreCase("soapbinding") || operation.getPort().getBindingType().equalsIgnoreCase("soap12binding") ){
            showSOAPOperationInformationPanel();
            return;
        }
    }
    
    private void showHTTPOperationInformationPanel(){
        if(httpOperationInformationPanel == null){
            httpOperationInformationPanel = new HTTPOperationInformationPanel(operation);
        }else{
            httpOperationInformationPanel.setOperation(operation);
        }
        
        if(httpOperationInformationPanel.getParent() != displayPanel){
            displayPanel.removeAll();
            displayPanel.add(httpOperationInformationPanel);
        }
    }
    
    
    private void showSOAPOperationInformationPanel(){
        if(soapOperationInformationPanel == null){
            soapOperationInformationPanel = new SOAPOperationInformationPanel(operation);
        }else{
            soapOperationInformationPanel.setOperation(operation);
        }
        
        if(soapOperationInformationPanel.getParent() != displayPanel){
            displayPanel.removeAll();
            displayPanel.add(soapOperationInformationPanel);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        supportedPanel = new javax.swing.JLabel();
        displayPanel = new javax.swing.JPanel();

        setName("Form"); // NOI18N

        supportedPanel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gui.WSFApplication.class).getContext().getResourceMap(InformationPanel.class);
        supportedPanel.setText(resourceMap.getString("supportedPanel.text")); // NOI18N
        supportedPanel.setName("supportedPanel"); // NOI18N
        supportedPanel.setOpaque(true);

        displayPanel.setName("displayPanel"); // NOI18N
        displayPanel.setLayout(new java.awt.GridLayout(0, 1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(supportedPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE)
            .addComponent(displayPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(supportedPanel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(displayPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel displayPanel;
    private javax.swing.JLabel supportedPanel;
    // End of variables declaration//GEN-END:variables
    
    private HTTPOperationInformationPanel httpOperationInformationPanel;
    private SOAPOperationInformationPanel soapOperationInformationPanel;
}
